package cn.lingyangwl.agile.auth.model.rqrs;

import cn.hutool.core.util.StrUtil;
import cn.lingyangwl.agile.model.constants.ValidationCons;
import cn.lingyangwl.agile.model.enums.TerminalEnum;
import cn.lingyangwl.framework.data.mate.annotations.FieldSensitive;
import cn.lingyangwl.framework.data.mate.fieldsensitive.enums.StrategyType;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * 授权用户保存请求
 *
 * @author shenguangyang
 */
@Data
@Accessors(chain = true)
public class AuthUserSaveReq {
    @ApiModelProperty(value = "证件号")
    private String idCard;

    @ApiModelProperty(value = "第三方的openId, 可选")
    private String openId;

    @ApiModelProperty(value = "用户真实姓名")
    private String realName;

    @ApiModelProperty(value = "用户昵称")
    private String nickName;

    @ApiModelProperty(value = "用户邮箱")
    @FieldSensitive(StrategyType.EMAIL)
    private String email;

    @ApiModelProperty(value = "手机号码")
    @FieldSensitive(StrategyType.MOBILE_PHONE)
    private String phone;

    @ApiModelProperty(value = "用户性别, 1=男,0=女,-1=未知")
    private String sex;

    @ApiModelProperty(value = "用户头像")
    private String avatar;

    @ApiModelProperty(value = "用户生日")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date birthday;

    @ApiModelProperty(value = "用户账号", example = "admin")
    @NotBlank(message = ValidationCons.NOT_EMPTY)
    @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成")
    @Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符")
    private String username;

    @ApiModelProperty(value = "密码", example = "123456")
    @NotEmpty(message = ValidationCons.NOT_EMPTY)
    @Length(min = 4, max = 16, message = "密码长度为 4-16 位")
    private String password;

    /**
     * @see TerminalEnum
     */
    @ApiModelProperty(value = "终端")
    private String terminal;

    public void setTerminal(String terminal) {
        this.terminal = StrUtil.emptyToDefault(terminal, TerminalEnum.OTHER.getTerminal());
    }
}
